//
//  DayPickerViewController.m
//  MoneyBook
//
//  Created by Justin Kim on 11. 6. 29..
//  Copyright 2011 Daum. All rights reserved.
//

#import "DayPickerViewController.h"


@implementation DayPickerViewController

@synthesize dayPickerView = _dayPickerView;
@synthesize showLabel = _showLabel;
@synthesize applyBtn = _applyBtn;
@synthesize cancelBtn = _cancelBtn;

/////////////////////////////////////////////////////////////////////////////////////////////////
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

/////////////////////////////////////////////////////////////////////////////////////////////////
- (void)dealloc{
    [_applyBtn release];
    [_cancelBtn release];
    [_showLabel release];
    [_dayPickerView release];
  [super dealloc];
}

/////////////////////////////////////////////////////////////////////////////////////////////////
- (void)didReceiveMemoryWarning{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/////////////////////////////////////////////////////////////////////////////////////////////////
- (void)viewDidLoad{
    [super viewDidLoad];
    self.title = @"등록일 선택";
    self.dayPickerView.datePickerMode = UIDatePickerModeDate;
	self.dayPickerView.hidden = NO;
	self.dayPickerView.date = [NSDate date];
	[self.dayPickerView addTarget:self
                           action:@selector(changeDateInLabel:)
                 forControlEvents:UIControlEventAllEvents];
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
	df.dateStyle = NSDateFormatterLongStyle;
    [self.showLabel setText:[NSString stringWithFormat:@"%@", [df stringFromDate:[NSDate date]]]];
	[df release];
}

/////////////////////////////////////////////////////////////////////////////////////////////////
- (void)viewDidUnload{
    self.applyBtn=nil;
    self.cancelBtn=nil;
    self.showLabel=nil;
    self.dayPickerView = nil;
  [super viewDidUnload];
}

/////////////////////////////////////////////////////////////////////////////////////////////////
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(void)setMode{
    [self.dayPickerView setDatePickerMode:UIDatePickerModeDate];
}
#pragma mark -
#pragma mark UIDatePickerViewDelegate
/////////////////////////////////////////////////////////////////////////////////////////////////
-(void)changeDateInLabel:(id)sender{
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
	df.dateStyle = NSDateFormatterLongStyle;
    [self.showLabel setText:[NSString stringWithFormat:@"%@", [df stringFromDate:_dayPickerView.date]]];
	[df release];
}
#pragma mark -
#pragma mark UIButtonDelegate
/////////////////////////////////////////////////////////////////////////////////////////////////
-(IBAction)applyAct:(id)sender{
    NSLog(@"applyAct");
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
	df.dateStyle = NSDateFormatterLongStyle;
    [_resultDelegate applyResultSet:self resultDic:[NSMutableDictionary dictionaryWithObjectsAndKeys:[_dayPickerView date], @"writeDay",
                                                    [NSString stringWithFormat:@"%@", [df stringFromDate:_dayPickerView.date]], @"showName",
                                                    nil]];

	[df release];
    [[self navigationController] popViewControllerAnimated:YES];
}
/////////////////////////////////////////////////////////////////////////////////////////////////
-(IBAction)cancelAct:(id)sender{
    NSLog(@"cancelAct");
    [[self navigationController] popViewControllerAnimated:YES];
}

@end
